import numpy as np
a1 = np.arange(12).reshape((3,4)).astype("float")
a1[1,2:] = np.nan
print(a1)
for i in range(a1.shape[1]):
    s = a1[:,i]
    nan_num = np.count_nonzero(s!=s)
    print(nan_num)
    if nan_num !=0:
        ss=s[s==s]
        s[np.isnan(s)]=ss.mean()
print(a1)
